e0a4b7c891b1bf84c8f5be8b085a3f41948d12f0,plugins/dedicated-resources/src/org/apache/cloudstack/dedicated/DedicatedResourceManagerImpl.java,DedicatedResourceManagerImpl,dedicateHost,#number#number#String#,516
Before Change
boolean domainIdInChildreanList = getDomainChildIds(dedicatedClusterOfHost.getDomainId()).contains(domainId);
//can dedicate a host to an account/domain if cluster is dedicated to parent-domain
if (dedicatedClusterOfHost.getAccountId() != null || (accountId == null && !domainIdInChildreanList) ||
(accountId != null && !(dedicatedClusterOfHost.getDomainId() == domainId || domainIdInChildreanList))) {
ClusterVO cluster = _clusterDao.findById(host.getClusterId());
s_logger.error("Host's Cluster " + cluster.getName() + " is already dedicated");
throw new CloudRuntimeException("Host's Cluster " + cluster.getName() + " is already dedicated");
}
}
if (dedicatedPodOfHost != null) {
boolean domainIdInChildreanList = getDomainChildIds(dedicatedPodOfHost.getDomainId()).contains(domainId);
//can dedicate a host to an account/domain if pod is dedicated to parent-domain
if (dedicatedPodOfHost.getAccountId() != null || (accountId == null && !domainIdInChildreanList) ||
(accountId != null && !(dedicatedPodOfHost.getDomainId() == domainId || domainIdInChildreanList))) {
HostPodVO pod = _podDao.findById(host.getPodId());
s_logger.error("Host's Pod " + pod.getName() + " is already dedicated");
throw new CloudRuntimeException("Host's Pod " + pod.getName() + " is already dedicated");
}
}
if (dedicatedZoneOfHost != null) {
boolean domainIdInChildreanList = getDomainChildIds(dedicatedZoneOfHost.getDomainId()).contains(domainId);
//can dedicate a host to an account/domain if zone is dedicated to parent-domain
if (dedicatedZoneOfHost.getAccountId() != null || (accountId == null && !domainIdInChildreanList) ||
(accountId != null && !(dedicatedZoneOfHost.getDomainId() == domainId || domainIdInChildreanList))) {
DataCenterVO zone = _zoneDao.findById(host.getDataCenterId());
s_logger.error("Host's Data Center " + zone.getName() + " is already dedicated");
throw new CloudRuntimeException("Host's Data Center " + zone.getName() + " is already dedicated");
After Change
@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_DEDICATE_RESOURCE, eventDescription = "dedicating a Host")
public List<DedicatedResourceVO> dedicateHost(final Long hostId, final Long domainId, final String accountName) {
Long accountId = null;
if (accountName != null) {
Account caller = CallContext.current().getCallingAccount();
Account owner = _accountMgr.finalizeOwner(caller, accountName, domainId, null);
accountId = owner.getId();
}
checkAccountAndDomain(accountId, domainId);
HostVO host = _hostDao.findById(hostId);
if (host == null) {
throw new InvalidParameterValueException("Unable to find host by id " + hostId);
} else {
//check if host is of routing type
if (host.getType() != Host.Type.Routing) {
throw new CloudRuntimeException("Invalid host type for host " + host.getName());
}
DedicatedResourceVO dedicatedHost = _dedicatedDao.findByHostId(hostId);
DedicatedResourceVO dedicatedClusterOfHost = _dedicatedDao.findByClusterId(host.getClusterId());
DedicatedResourceVO dedicatedPodOfHost = _dedicatedDao.findByPodId(host.getPodId());
DedicatedResourceVO dedicatedZoneOfHost = _dedicatedDao.findByZoneId(host.getDataCenterId());
if (dedicatedHost != null) {
s_logger.error("Host " + host.getName() + " is already dedicated");
throw new CloudRuntimeException("Host " + host.getName() + " is already dedicated");
}
if (dedicatedClusterOfHost != null) {
boolean domainIdInChildreanList = getDomainChildIds(dedicatedClusterOfHost.getDomainId()).contains(domainId);
//can dedicate a host to an account/domain if cluster is dedicated to parent-domain
if (dedicatedClusterOfHost.getAccountId() != null || (accountId == null && !domainIdInChildreanList) ||
(accountId != null && !(dedicatedClusterOfHost.getDomainId().equals(domainId) || domainIdInChildreanList))) {
ClusterVO cluster = _clusterDao.findById(host.getClusterId());
s_logger.error("Host's Cluster " + cluster.getName() + " is already dedicated");
throw new CloudRuntimeException("Host's Cluster " + cluster.getName() + " is already dedicated");
}
}
if (dedicatedPodOfHost != null) {
boolean domainIdInChildreanList = getDomainChildIds(dedicatedPodOfHost.getDomainId()).contains(domainId);
//can dedicate a host to an account/domain if pod is dedicated to parent-domain
if (dedicatedPodOfHost.getAccountId() != null || (accountId == null && !domainIdInChildreanList) ||
(accountId != null && !(dedicatedPodOfHost.getDomainId().equals(domainId) || domainIdInChildreanList))) {
HostPodVO pod = _podDao.findById(host.getPodId());
s_logger.error("Host's Pod " + pod.getName() + " is already dedicated");
throw new CloudRuntimeException("Host's Pod " + pod.getName() + " is already dedicated");
}
}
if (dedicatedZoneOfHost != null) {
boolean domainIdInChildreanList = getDomainChildIds(dedicatedZoneOfHost.getDomainId()).contains(domainId);
//can dedicate a host to an account/domain if zone is dedicated to parent-domain
if (dedicatedZoneOfHost.getAccountId() != null || (accountId == null && !domainIdInChildreanList) ||
(accountId != null && !(dedicatedZoneOfHost.getDomainId().equals(domainId) || domainIdInChildreanList))) {
DataCenterVO zone = _zoneDao.findById(host.getDataCenterId());
s_logger.error("Host's Data Center " + zone.getName() + " is already dedicated");
throw new CloudRuntimeException("Host's Data Center " + zone.getName() + " is already dedicated");